package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 42
 * @date 2025/3/30
 * @Description
 */
@Mapper
public interface ShopCartMapper {
    /**
     * 查询购物车数据，查看用户是否有这条信息
     * @param shoppingCart
     * @return
     */
    ShoppingCart select(ShoppingCart shoppingCart);

    /**
     * 更新用户购物车数量 +1
     * @param info
     */
    @Update("UPDATE shopping_cart SET number = #{number} WHERE id = #{id}")
    void update(ShoppingCart info);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    void insert(ShoppingCart shoppingCart);

    /**
     * 查看购物车数据
     * @param userId
     * @return
     */
    List<ShoppingCart> list(Long userId);

    /**
     * 清空用户购物车
     * @param userId
     */
    @Delete("DELETE FROM shopping_cart WHERE user_id = #{userId}")
    void deleteByUserId(Long userId);

    @Delete("DELETE FROM shopping_cart WHERE id = #{id}")
    void deleteById(Long id);

    /**
     * 批量插入购物车
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
